package com.qzl.server.handler;

import com.qzl.common.netty.handler.MessageFactory;
import com.qzl.common.netty.handler.MessageHandler;
import com.qzl.common.netty.message.Message;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class BusinessHandler extends SimpleChannelInboundHandler<Message> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Message msg) throws Exception {
        System.out.println("收到统一消息: " + msg.getContent());
        // 处理消息
        MessageHandler messageHandler = MessageFactory.getInvokeStrategy(msg.getMessageType());
        if (messageHandler == null){
            log.error("未找到对应的处理策略");
        } else {
            messageHandler.handle(ctx, msg);
        }
        // 回复客户端
//        Message message = new Message();
//        message.setContent("服务器已收到消息");
//        ResponseUtils.sendCtxResponse(ctx, message);
    }
}
